﻿/*
* 创建者：LIYINFAI
* 创建时间：2023/10/24 9:35:26
* 描述：
* --------------------------------------
* 修改说明：
* --------------------------------------
*/
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Windows.Forms;

namespace CommonLibrary
{
    /// <summary>
    /// 颜色配置
    /// </summary>
    public class ColorSettings
    {
        /// <summary>
        /// 窗体边框颜色
        /// </summary>
        public static Color FORM_BORDER_COLOR = Color.FromArgb(30, 56, 83);
        /// <summary>
        /// 按钮背景颜色
        /// </summary>
        public static Color BUTTON_BACK_COLOR = Color.FromArgb(35, 45, 55);
        /// <summary>
        /// 标题栏背景颜色
        /// </summary>
        public static Color TITLE_BACK_BAR = Color.FromArgb(35, 45, 55);
        /// <summary>
        /// 标题栏前景颜色
        /// </summary>
        public static Color TITLE_FORE_BAR = Color.White;
        /// <summary>
        /// 状态栏背景颜色
        /// </summary>
        public static Color STATUSSTRIP_BACK_COLOR = Color.FromArgb(30, 56, 83);
        /// <summary>
        /// 菜单栏背景颜色
        /// </summary>
        public static Color MENUSTRIP_BACK_COLOR = Color.WhiteSmoke;//Color.FromArgb(30, 56, 83);
        /// <summary>
        /// DataGridView头部背景颜色
        /// </summary>
        public static Color DATAGRIDVIEW_HEADER_BACK_COLOR = Color.FromArgb(35, 45, 55);
        /// <summary>
        /// DataGridView头部前景颜色
        /// </summary>
        public static Color DATAGRIDVIEW_HEADER_FORE_COLOR = Color.White;
        /// <summary>
        /// DataGridView选中头部背景颜色
        /// </summary>
        public static Color DATAGRIDVIEW_HEADER_SELECTED_BACK_COLOR = Color.FromArgb(35, 45, 55);
        /// <summary>
        /// DataGridView选中头部前景颜色
        /// </summary>
        public static Color DATAGRIDVIEW_HEADER_SELECTED_FORE_COLOR = Color.White;
        /// <summary>
        /// DataGridView选中单元格背景颜色
        /// </summary>
        public static Color DATAGRIDVIEW_CELL_SELECTED_BACK_COLOR = Color.FromArgb(35, 45, 55);
        /// <summary>
        /// DataGridView选中单元格前景颜色
        /// </summary>
        public static Color DATAGRIDVIEW_CELL_SELECTED_FORE_COLOR = Color.Black;
        /// <summary>
        /// DataGridView默认单元格背景颜色
        /// </summary>
        public static Color DATAGRIDVIEW_CELL_DEFAULT_BACK_COLOR = Color.FromArgb(48, 60, 67);
        /// <summary>
        /// DataGridView默认单元格背前景颜色
        /// </summary>
        public static Color DATAGRIDVIEW_CELL_DEFAULT_FORE_COLOR = Color.White;
        /// <summary>
        /// 连接信息
        /// </summary>
        public static Color LABEL_CONNECTION_COLOR = Color.FromArgb(30, 56, 83);
        /// <summary>
        /// 字体
        /// </summary>
        public static Font DATAGRIDVIEW_CELL_FONT = new Font("微软雅黑", 12, FontStyle.Bold);
        /// <summary>
        /// TabPage头部选中前景颜色
        /// </summary>
        public static Color TabHeaderSelectedForeColor = Color.White;
        /// <summary>
        /// TabPage头部选中背景颜色
        /// </summary>
        public static Color TabHeaderSelectedBackColor = Color.FromArgb(35, 45, 55);
        /// <summary>
        /// TabPage头部默认背景颜色
        /// </summary>
        public static Color TabHeaderDefaultBackColor = Color.WhiteSmoke;
        /// <summary>
        /// 启动画面背景颜色
        /// </summary>
        public static Color SplashFormBackColor = Color.FromArgb(48, 60, 67);
        /// <summary>
        /// 常规日志信息前景颜色
        /// </summary>
        public static Color NORMAL_LOG_FORE_COLOR = Color.White;
    }
    /// <summary>
    /// 菜单绘制
    /// </summary>
    public class MenuStripRender : ToolStripProfessionalRenderer
    {
        /// <summary>
        /// 绘制背景
        /// </summary>
        /// <param name="e"></param>
        protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStripMenuItem menuItem = e.Item as ToolStripMenuItem;
            if (menuItem != null && menuItem.HasDropDownItems)
            {
                Rectangle rectangle = new Rectangle(Point.Empty, e.Item.Size);
                using (SolidBrush brush = new SolidBrush(ColorSettings.TITLE_BACK_BAR))
                {
                    e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                    using (GraphicsPath path = CreateRoundRectPath(rectangle, 10))
                    {
                        e.Graphics.FillPath(brush, path);
                    }
                }
            }
            else
            {
                base.OnRenderMenuItemBackground(e);
            }
        }
        /// <summary>
        /// 绘制边框
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="cornerRadius"></param>
        /// <returns></returns>
        private GraphicsPath CreateRoundRectPath(Rectangle rect, int cornerRadius)
        {
            GraphicsPath roundedRect = new GraphicsPath();
            roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
            roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
            roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
            roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
            roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
            roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
            roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
            roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
            roundedRect.CloseFigure();
            return roundedRect;
        }
    }
}
